package com.leff.cards.ui.util;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.leff.cards.R;
import com.leff.cards.data.AppState;
import com.leff.cards.data.User;

public class UserListAdapter extends BaseAdapter {

	private Context mContext;
	private ArrayList<User> mData;
	
	public UserListAdapter(Context C) {
		mContext = C;
		dataRefreshed();
	}
	
	public void dataRefreshed() {
		mData = AppState.get().getActiveGroup().members;
		this.notifyDataSetChanged();
	}
	
	@Override
	public int getCount() {
		return mData.size();
	}

	@Override
	public Object getItem(int pos) {
		return mData.get(pos);
	}

	@Override
	public long getItemId(int pos) {
		return Long.valueOf(mData.get(pos).id);
	}

	@Override
	public View getView(int pos, View convertView, ViewGroup parent) {

		View V = convertView;
		if(V == null) {
			V = LayoutInflater.from(mContext).inflate(R.layout.user_list_item, null);
		}
		
		TextView name = (TextView)V.findViewById(R.id.user_name);
		TextView email = (TextView)V.findViewById(R.id.user_email);
		
		User U = mData.get(pos);
		
		name.setText(U.displayName);
		email.setText("" + U.fbid);
		
		return V;
	}

}
